<template>
	<view>
		<uni-list class="setting-list">
			<uni-list-item showArrow title="宝宝头像" :thumb="babyInfo.avatar" />
			<uni-list-item showArrow title="昵称" :rightText="babyInfo.nickname" />
			<uni-list-item showArrow title="性别" :rightText="babyInfo.gender === 1 ? '男' : '女'" />
			<uni-list-item showArrow title="出生年月" :rightText="formatDate(babyInfo.birthday)" />
			<uni-list-item showArrow title="身高" :rightText="babyInfo.height + 'cm'" />
			<uni-list-item showArrow title="体重" :rightText="babyInfo.weight + 'kg'" />
		</uni-list>
	</view>
</template>

<script setup>
import { ref, onMounted } from 'vue';

const babyInfo = ref({
    avatar: '',
    nickname: '',
    gender: '',
    birthday: '',
    height: '',
    weight: '',
    id: ''
});

const getBabyInfo = async () => {
    try {
        const res = await uni.request({
            method: 'GET',
			url: 'http://localhost:9100/api/baby/selectById',		
            data: {
                babyId: uni.getStorageSync('babyId'),
                userId: uni.getStorageSync('userId')
            },
			header: {
				'bece_token': uni.getStorageSync('bece_token') //自定义请求头信息
			}
        });
        
        if (res.data.code === 200) {
            babyInfo.value = res.data.data;
        } else {
            uni.showToast({
                title: res.data.message || '获取数据失败',
                icon: 'none'
            });
        }
    } catch (error) {
        uni.showToast({
            title: '网络请求失败',
            icon: 'none'
        });
    }
};

const formatDate = (date) => {
    if (!date) return '';
    return new Date(date).toLocaleDateString('zh-CN');
};

onMounted(() => {
    getBabyInfo();
});
</script>

<style scoped>
.uni-list-item__content-title{
	font-size: 30rpx !important;
}
.uni-list-item__extra-text{
	font-size: 30rpx !important;
}	   
</style>